const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userType:'',
    messageInfo:'',
    deal_count:'',
    system_count:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideHomeButton()
    this.setData({
      userType: wx.getStorageSync('userType')
    })
    this.messageInfo();
  },
  // 消息
  messageInfo:function(){
    console.log('消息-------------------------------')
    var _this = this
    var url = app.globalData.baseUrl + 'user/Message_home';
    var data = {
      token: app.globalData.token
    }
    wx.showLoading({
      title: '加载中',
    })
    app.wxGetRequest(url, data, (res) => {
      wx.hideLoading()
      var messageInfo = res.data
      let deal_count=messageInfo.deal_count
      let system_count=messageInfo.system_count
      if(deal_count>99){
        deal_count="99+"
      }
      if(system_count>99){
        system_count="99+"
      }
      if (messageInfo.deal_mes){
        messageInfo.deal_mes.message_content ='<p style="color: #595959;font-size: 14px;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;word-break: break-all;">'+ messageInfo.deal_mes.message_content+'</p>'
      }
      if (messageInfo.system_mes) {
        messageInfo.system_mes.message_content ='<p style="color: #595959;font-size: 14px;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;word-break: break-all;">'+ messageInfo.system_mes.message_content+'</p>'
      }
      if (res.code == 1000) {
        _this.setData({
          messageInfo,
          deal_count,
          system_count
        })
      } else {
        wx.showToast({
          title: res.message,
          icon: 'none',
          duration: 2000
        })
      }
    }, () => {
      wx.hideLoading()
    })
  },

  // 消息列表
  messageBtn:function(e){
    var { type } = e.currentTarget.dataset
    wx.navigateTo({
      url: '/userPage/pages/transactionDynamic/transactionDynamic?type=' + type,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
       wx.hideHomeButton()
      this.messageInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
